package com.library.web.controller.library;


import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.MbGift;
import com.library.domain.MbSignRulesGift;
import com.library.service.IMbGiftService;
import com.library.service.IMbSignRulesGiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 规则礼品关联 信息操作处理
 *
 * @author null
 * @date 2020-04-23
 * @blame Android Team
 */
@RestController
@RequestMapping("/mobile/mbSignRulesGift")
public class MbSignRulesGiftController extends BaseController {
    private String prefix = "business/mobile/mbSignRules/data";

    @Autowired
    private IMbSignRulesGiftService mbSignRulesGiftService;
    @Autowired
    private IMbGiftService mbGiftService;

    @GetMapping()
    public String mbSignRulesGift() {
        return prefix + "/mbSignRulesGift";
    }

    /**
     * 查询规则礼品关联列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MbSignRulesGift mbSignRulesGift) {
        startPage();
        List<MbSignRulesGift> list = mbSignRulesGiftService.selectMbSignRulesGiftList(mbSignRulesGift);
        return getDataTable(list);
    }


    /**
     * 导出规则礼品关联列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MbSignRulesGift mbSignRulesGift) {
        List<MbSignRulesGift> list = mbSignRulesGiftService.selectMbSignRulesGiftList(mbSignRulesGift);
        ExcelUtil<MbSignRulesGift> util = new ExcelUtil<>(MbSignRulesGift.class);
        return util.exportExcel(list, "mbSignRulesGift");
    }

    /**
     * 新增规则礼品关联
     */
    @GetMapping("/add/{ruleId}")
    public String add(@PathVariable("ruleId") Integer ruleId, ModelMap map) {
        MbGift mbGift = new MbGift();
        List<MbGift> mbGifts = mbGiftService.selectMbGiftList(mbGift);
        map.put("mbGiftList", mbGifts);
        map.put("ruleId", ruleId);
        return prefix + "/add";
    }

    /**
     * 新增保存规则礼品关联
     */
    @Log(title = "规则礼品关联", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MbSignRulesGift mbSignRulesGift) {
        return toAjax(mbSignRulesGiftService.insertMbSignRulesGift(mbSignRulesGift));
    }

    /**
     * 修改规则礼品关联
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        MbSignRulesGift mbSignRulesGift = mbSignRulesGiftService.selectMbSignRulesGiftById(id);
        mmap.put("mbSignRulesGift", mbSignRulesGift);
        return prefix + "/edit";
    }

    /**
     * 修改保存规则礼品关联
     */
    @Log(title = "规则礼品关联", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MbSignRulesGift mbSignRulesGift) {
        return toAjax(mbSignRulesGiftService.updateMbSignRulesGift(mbSignRulesGift));
    }

    /**
     * 删除规则礼品关联
     */
    @Log(title = "规则礼品关联", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(mbSignRulesGiftService.deleteMbSignRulesGiftByIds(ids));
    }

}
